#include<vector>
#include<string>
#include<unordered_set>
using namespace std;

class MagicDictionary {
private:
    unordered_set<string> set;
public:
    /** Initialize your data structure here. */
    MagicDictionary() {

    }

    /** Build a dictionary through a list of words */
    void buildDict(vector<string> dict) {
        for (auto& str : dict) {
            set.insert(str);
        }
    }

    /** Returns if there is any word in the trie that equals to the given word after modifying exactly one character */
    bool search(string word) {
        for (int i = 0; i < word.size(); ++i) {
            for (char c = 'a'; c < 'z'; ++c) {
                if (word[i] == c) continue;
                char tmp = word[i];
                word[i] = c;
                if (set.find(word) != set.end())
                    return true;
                word[i] = tmp;
            }
        }
        return false;
    }
};

/**
 * Your MagicDictionary object will be instantiated and called as such:
 * MagicDictionary* obj = new MagicDictionary();
 * obj->buildDict(dict);
 * bool param_2 = obj->search(word);
 */